﻿namespace LeadMaster.Controllers
{
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.Entity;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using LeadMaster.Models;
  using LeadMaster.DAL;
  using System.IO;
  using LeadMaster.Helpers;

    public class LeadsReplacementController : Controller
    {
        private DunsmoreContext db = new DunsmoreContext();

        //
        // GET: /LeadsReplacement/

        public ActionResult Index()
        {
          Maintenance.inMaintenance = true;
          return View(db.LeadsReplacement.ToList());
        }

        //
        // GET: /LeadsReplacement/Details/5

        public ActionResult Details(int id = 0)
        {
            LeadsReplacement leadsreplacement = db.LeadsReplacement.Find(id);
            if (leadsreplacement == null)
            {
                return HttpNotFound();
            }
            return View(leadsreplacement);
        }

        //
        // GET: /LeadsReplacement/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /LeadsReplacement/Create

        [HttpPost]
        public ActionResult Create(LeadsReplacement leadsreplacement, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                db.LeadsReplacement.Add(leadsreplacement);
                db.SaveChanges();
                if (file.ContentLength > 0)
                {
                    var fileName = Path.GetFileName(file.FileName);
                    var path = Path.Combine(Server.MapPath("~/Docs/LeadsReplacementDocs"), fileName);
                    file.SaveAs(path);
                }
                return RedirectToAction("Index");
            }

            return View(leadsreplacement);
        }

        //
        // GET: /LeadsReplacement/Edit/5

        public ActionResult Edit(int id = 0)
        {
            LeadsReplacement leadsreplacement = db.LeadsReplacement.Find(id);
            if (leadsreplacement == null)
            {
                return HttpNotFound();
            }
            return View(leadsreplacement);
        }

        //
        // POST: /LeadsReplacement/Edit/5

        [HttpPost]
        public ActionResult Edit(LeadsReplacement leadsreplacement)
        {
            if (ModelState.IsValid)
            {
                db.Entry(leadsreplacement).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(leadsreplacement);
        }

        //
        // GET: /LeadsReplacement/Delete/5

        public ActionResult Delete(int id = 0)
        {
            LeadsReplacement leadsreplacement = db.LeadsReplacement.Find(id);
            if (leadsreplacement == null)
            {
                return HttpNotFound();
            }
            return View(leadsreplacement);
        }

        //
        // POST: /LeadsReplacement/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            LeadsReplacement leadsreplacement = db.LeadsReplacement.Find(id);
            db.LeadsReplacement.Remove(leadsreplacement);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}